import Vue from 'vue';
import axios from 'axios';
import ElementUI from 'element-ui';
import { codemirror } from 'vue-codemirror';
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/ambiance.css';
import 'codemirror/addon/hint/show-hint.css';
import App from './App.vue';
import router from './router';
import store from './store';
import qs from 'qs';
import 'element-ui/lib/theme-chalk/index.css';

import './common.less';

Vue.use(codemirror);

Vue.use(ElementUI, { zIndex: 1000 });
axios.defaults.headers.post['Content-Type'] = 'Content-Type:application/x-www-form-urlencoded; charset=UTF-8';
Vue.prototype.$axios = axios;
Vue.prototype.HOST = 'api';
Vue.config.productionTip = false;

Vue.prototype.HOST = 'api';

// axios.interceptors.request.use(config => {
//   if(config.method  === 'post'){
//         config.data = qs.stringify(config.data);
//     }
//   return config
// }, error => {
//   Promise.reject(error)
// })
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.transformRequest = [function (data) {
    let src = ''
    for (let item in data) {
      src += encodeURIComponent(item) + '=' + encodeURIComponent(data[item]) + '&'
    }
    return src
}]


new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app');

